<template>
    <el-dialog
      :title="!dataForm.id ? '新增' : '修改'"
      :close-on-click-modal="false"
      :visible.sync="visible"
    >
      <el-form
        :model="dataForm"
        :rules="dataRule"
        ref="dataForm"
        @keyup.enter.native="dataFormSubmit()"
        label-width="162px"
      >
        <el-form-item label="所属项目" prop="companyName">
          <el-input
            v-model="dataForm.companyName"
            placeholder="所属项目"
          ></el-input>
        </el-form-item>
        <el-form-item label="车辆所属公司" prop="companyAddress">
          <el-input
            v-model="dataForm.companyAddress"
            placeholder="车辆所属公司"
          ></el-input>
        </el-form-item>
        <el-form-item label="车牌号" prop="adminDivisionitemId">
          <el-input
            v-model="dataForm.adminDivisionitemId"
            placeholder="车牌号"
          ></el-input>
        </el-form-item>
        <el-form-item label="离开出土场抓拍照片" prop="orgCode">
          <el-input
            v-model="dataForm.orgCode"
            placeholder="离开出土场抓拍照片"
          ></el-input>
        </el-form-item>
        <el-form-item label="离开出土场抓拍时间" prop="email">
          <el-input v-model="dataForm.email" placeholder="离开出土场抓拍时间"></el-input>
        </el-form-item>
        <el-form-item label="进入消纳场抓拍照片" prop="contactPhone">
          <el-input
            v-model="dataForm.contactPhone"
            placeholder="进入消纳场抓拍照片"
          ></el-input>
        </el-form-item>
        <el-form-item label="进入消纳场抓拍时间" prop="legalUser">
          <el-input
            v-model="dataForm.legalUser"
            placeholder="进入消纳场抓拍时间"
          ></el-input>
        </el-form-item>
        <el-form-item label="运输路线轨迹图" prop="legalUser">
          <el-input
            v-model="dataForm.legalUser"
            placeholder="运输路线轨迹图"
          ></el-input>
        </el-form-item>
        <el-form-item label="状态" prop="legalUser">
          <el-input
            v-model="dataForm.legalUser"
            placeholder="状态"
          ></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="visible = false">取消</el-button>
        <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
      </span>
    </el-dialog>
  </template>
  
  <script>
  import { isEmail, isIdCard } from "@/utils/validate";
  export default {
    data() {
      return {
        options: [],
        visible: false,
        dataForm: {
          id: 0,
          companyName: "",
          companyAddress: "",
          adminDivisionitemId: "",
          typeId: "",
          orgCode: "",
          establishDate: "",
          email: "",
          contactPhone: "",
          legalUser: "",
          legalUserIdNumber: ""
        },
        dataRule: {
        }
      };
    },
    methods: {
      // 获取公司类型
      getCompanyTypes() {
        this.$http({
          url: this.$http.adornUrl(`/sys/getParamenters/getCompanyType`),
          method: "get"
        }).then(({ data }) => {
          if (data && data.code === 0) {
            this.options = data.list;
          }
        });
      },
      init(id) {
        this.getCompanyTypes();
        this.dataForm.id = id || 0;
        this.visible = true;
        this.$nextTick(() => {
          this.$refs["dataForm"].resetFields();
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/sys/bcompany/info/${this.dataForm.id}`),
              method: "get",
              params: this.$http.adornParams()
            }).then(({ data }) => {
              if (data && data.code === 0) {
                this.dataForm.companyName = data.bCompany.companyName;
                this.dataForm.companyAddress = data.bCompany.companyAddress;
                this.dataForm.adminDivisionitemId =
                  data.bCompany.adminDivisionitemId;
                this.dataForm.typeId = data.bCompany.typeId;
                this.dataForm.orgCode = data.bCompany.orgCode;
                this.dataForm.establishDate = data.bCompany.establishDate;
                this.dataForm.email = data.bCompany.email;
                this.dataForm.contactPhone = data.bCompany.contactPhone;
                this.dataForm.legalUser = data.bCompany.legalUser;
                this.dataForm.legalUserIdNumber = data.bCompany.legalUserIdNumber;
              }
            });
          }
        });
      },
      // 表单提交
      dataFormSubmit() {
        this.$refs["dataForm"].validate(valid => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(
                `/sys/bcompany/${!this.dataForm.id ? "save" : "update"}`
              ),
              method: "post",
              data: this.$http.adornData({
                id: this.dataForm.id || undefined,
                companyName: this.dataForm.companyName,
                companyAddress: this.dataForm.companyAddress,
                adminDivisionitemId: this.dataForm.adminDivisionitemId,
                typeId: this.dataForm.typeId,
                orgCode: this.dataForm.orgCode,
                establishDate: this.dataForm.establishDate,
                email: this.dataForm.email,
                contactPhone: this.dataForm.contactPhone,
                legalUser: this.dataForm.legalUser,
                legalUserIdNumber: this.dataForm.legalUserIdNumber
              })
            }).then(({ data }) => {
              if (data && data.code === 0) {
                this.$message({
                  message: "操作成功",
                  type: "success",
                  duration: 1500,
                  onClose: () => {
                    this.visible = false;
                    this.$emit("refreshDataList");
                  }
                });
              } else {
                this.$message.error(data.msg);
              }
            });
          }
        });
      }
    }
  };
  </script>
  